Skip to content

Conversation

@c8ef
Copy link
Contributor

@c8ef c8ef commented Dec 15, 2025

This patch adds the IN6_IS_ADDR_LOOPBACK macro, which checks whether an address is loopback address.

@c8ef c8ef marked this pull request as ready for review December 15, 2025 15:01
@llvmbot llvmbot added the libc label Dec 15, 2025
Copy link
Contributor Author

c8ef commented Dec 15, 2025

@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2025

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/172312.diff

2 Files Affected:

  • (modified) libc/include/llvm-libc-macros/netinet-in-macros.h (+9)
  • (modified) libc/test/include/netinet_in_test.cpp (+5)
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
index f97a2dd0c3fda..3148aed6bb112 100644
--- a/libc/include/llvm-libc-macros/netinet-in-macros.h
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -44,6 +44,15 @@
    (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[2]) == 0 &&              \
    (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[3]) == 0)
 
+#define IN6_IS_ADDR_LOOPBACK(a)                                                \
+  ((__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[0]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[1]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[2]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[12]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[13]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[14]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[15]) == 1)
+
 #define IN6_IS_ADDR_LINKLOCAL(a)                                               \
   ((__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[0]) == 0xfe &&            \
    (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xc0) == 0x80)
diff --git a/libc/test/include/netinet_in_test.cpp b/libc/test/include/netinet_in_test.cpp
index d70c780800858..15e57ccef7ac5 100644
--- a/libc/test/include/netinet_in_test.cpp
+++ b/libc/test/include/netinet_in_test.cpp
@@ -19,6 +19,11 @@ TEST(LlvmLibcNetinetInTest, IN6Macro) {
     buff[i] = 0;
   }
 
+  EXPECT_FALSE(IN6_IS_ADDR_LOOPBACK(buff));
+  buff[15] = 1;
+  EXPECT_TRUE(IN6_IS_ADDR_LOOPBACK(buff));
+  buff[15] = 0;
+
   buff[0] = 0xfe;
   buff[1] = 0x80;
   EXPECT_TRUE(IN6_IS_ADDR_LINKLOCAL(buff));

Copy link
Contributor Author

c8ef commented Dec 18, 2025

Merge activity

  • Dec 18, 3:02 PM UTC: A user started a stack merge that includes this pull request via Graphite.

@c8ef c8ef force-pushed the users/c8ef/12-15-_libc_add_in6_is_addr_unspecified_ branch 2 times, most recently from 533e1f5 to 3a76cf5 Compare December 18, 2025 15:06
Base automatically changed from users/c8ef/12-15-_libc_add_in6_is_addr_unspecified_ to main December 18, 2025 15:06
@c8ef c8ef merged commit ecd46d3 into main Dec 18, 2025
22 of 26 checks passed
@c8ef c8ef deleted the users/c8ef/12-15-_libc_add_in6_is_addr_loopback_ branch December 18, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants